function getBIM(weight, height) {
	//BMI = 体重(公斤) / 身高^2(米^2)
	height = height / 100;
	let bmi = weight / Math.pow(height, 2);
	bmi = bmi.toFixed(1);
	return bmi
}

function bodyFat({
	weight,
	height,
	age,
	sex
}) {
	let personSex = sex == '男' ? 1 : 0
	let BMI = getBIM(weight, height)
	var TZL = 1.2 * BMI + 0.23 * age - 5.4 - 10.8 * personSex;
	TZL = TZL.toFixed(2);
	var minNum = (0.15 + 0.10 * (1 - personSex));
	var maxNum = (0.18 + 0.10 * (1 - personSex));
	return TZL
}

function getWeight({
	weight,
	height,
	sex
}) {
	let type = 1
	if (sex == '男') {
		var sbw = (height - 80) * 0.7;
	} else {
		var sbw = (height - 70) * 0.6;
	}
	var maxSbw = parseInt(sbw * 100 * 1.15) / 100;
	var minSbw = parseInt(sbw * 100 * 0.85) / 100;

	if (weight >= minSbw && weight <= maxSbw) {
		type = 1
	} else if (weight < minSbw) {
		type = 0
	} else if (weight > maxSbw) {
		type = 2
	}
	return {
		weightState: type,
		maxSbw: maxSbw,
		minSbw: minSbw
	}
}

export {
	getBIM,
	bodyFat,
	getWeight
}
